<template>
	<view class="Pay" :style="'background-Image: url('+ homebgc +');'">
		<view class="top"></view>
		<view class="left" @click="NavLeft"><text class="tn-icon-left"
				style="font-size: 35rpx;font-weight: bold;"></text></view>
		<view class="PayModel">
			<view class="title">年费会员 VIP</view>
			<view class="content">
				<view class="content_left">
					<text class="left1">限时优惠，立省</text>
					<text class="left2">¥ 190</text>
				</view>
				<view class="right">
					<text class="right1">¥</text>
					<text class="right2">{{amount}}</text>
					<text class="right3">原价¥289</text>
				</view>
			</view>
		</view>
		<view class="custom-style">
			<tn-button :blockRepeatClick="true" backgroundColor="#7265E3" size="lg" fontColor="#fff"
				@click="wxGetUserInfos">确认协议并支付开通</tn-button>
		</view>
		<view class="empower_title">提示: 虚拟商品，不支持退款，最终解释权归摩尔星光所有</view>
		<view class="empower">
			<tn-radio-group v-model="Uradio" @change="radios">
				<tn-radio activeColor="#F9DA88" name="one" shape="square">已了解</tn-radio>
			</tn-radio-group>
			<view class="empower_bom">
				<text class="py" @click="Recharge">《充值协议》</text><text class="d">、</text>
				<text class="py" @click="userag">《用户协议》</text><text class="d">、</text>
				<text class="py" @click="privacy">《隐私政策》</text>
			</view>
		</view>
		<tn-toast ref="toast"></tn-toast>
	</view>
</template>

<script>
	import {GetPayInfo} from "@/api/index.js"
	export default {

		data() {
			return {
				Uradio: '',
				amount:99,
				homebgc: this.$websiteUrl + 'static/web_files/Home_bj.svg',
				orderId: null, // 假设有一个订单ID
			}

		},

		methods: {
			async wxGetUserInfos(){
				// 展示加载框
				if (this.Uradio!='one') {
					this.$refs.toast.show({
						title: '警告',
						content: '请先勾选充值、用户、隐私等协议',
						icon: '',
						image: '',
						duration: 2000
					})
					return;
				}
				const data = {
					amount:this.amount*100
				}
				// console.log(data);
				const response = await GetPayInfo(data)
				if(response.code==2000){
					const res = response.data.result
					// 2. 调用微信支付
					wx.requestPayment({
						timeStamp: res.timeStamp,
						nonceStr: res.nonceStr,
						package: res.package,
						signType: res.signType,
						paySign: res.paySign,
						success: (res) => {
							if(res.errMsg=='requestPayment:ok'){
								this.$store.dispatch('fetchUserInfo');
								const data = {
									index: 3
								}
								const objStr = encodeURIComponent(JSON.stringify(data))
								wx.reLaunch({
									url: `/pages/index/index?userInfo=${objStr}`
								})
								setTimeout(()=>{
								wx.showToast({
									title: '支付成功',
									icon: 'success'
								});									
								},300)
							}
						},
						fail: (err) => {
							wx.showToast({
								title: '支付失败',
								icon: 'error'
							});
							console.error('支付失败：', err);
						}
					});
				}
			},
			NavLeft() {
				const data = {
					index: 3
				}
				const objStr = encodeURIComponent(JSON.stringify(data))
				wx.reLaunch({
					url: `/pages/index/index?userInfo=${objStr}`
				})
			},
			// 声明
			radios(e) {
				this.Uradio = 'one';
			},
			Recharge(){
				uni.$tn.route('/basicPage/login/Recharge/RechargeAgreement');
			},
			userag() {
				uni.$tn.route('/basicPage/login/userAgreement/userAgreement');
			},
			privacy() {
				uni.$tn.route('/basicPage/login/privacyPolicy/privacyPolicy');
			}

		},

	}
</script>

<style lang="scss" scoped>
	.Pay {
		position: relative;
		padding-top: 70rpx;
		height: 100vh;
		overflow: hidden;
		background-size: cover;
		background-position: center center;
		background-repeat: no-repeat;
		padding: 0 48rpx;

		.top {
			height: 88rpx;
		}

		.left {
			display: flex;
			align-items: center;
			height: 88rpx;
			margin-left: -30rpx;
		}

		.PayModel {
			margin-top: 84rpx;
			height: 176rpx;
			background: linear-gradient(180deg, #F2F2FB 0%, #F9DA88 100%);
			border-radius: 28rpx;
			padding: 42rpx 40rpx;
			margin-bottom: 100rpx;

			.title {
				margin-bottom: 14rpx;
				font-weight: 600;
				font-size: 32rpx;
				color: #2D3142;
			}

			.content {
				display: flex;
				justify-content: space-between;
				align-items: flex-end;
				margin-top: -24rpx;

				.content_left {
					height: 34rpx;
					font-weight: 400;
					font-size: 24rpx;
					color: #2D3142;

					.left2 {
						margin-left: 12rpx;
						font-weight: 600;
						font-size: 32rpx;
						color: #2D3142;
					}
				}

				.right {
					font-weight: 600;
					font-size: 32rpx;
					color: #FF5533;
					text-transform: uppercase;

					.right1 {
						margin-right: 12rpx;
					}

					.right2 {
						margin-right: 16rpx;
						font-weight: 600;
						font-size: 64rpx;
						color: #FF5533;
					}

					.right3 {
						font-weight: 400;
						font-size: 20rpx;
						color: #999999;
						line-height: 28rpx;
						text-decoration-line: line-through;
						text-transform: uppercase;
					}
				}
			}
		}

		.custom-style {
			width: 100%;
			padding: 0 48rpx;
			margin-bottom: 42rpx;

			::v-deep button {
				height: 104rpx !important;
				background: #F9DA88 !important;
				border-radius: 28rpx !important;
				width: 100% !important;
				border-radius: 28rpx !important;
				font-weight: 400 !important;
				font-size: 32rpx !important;
				color: #000 !important;

			}
		}

		.empower_title {
			padding: 0 48rpx;
			font-weight: 400;
			font-size: 22rpx;
			color: #818AA6;
			line-height: 42rpx;
		}

		.empower {
			display: flex;
			align-items: center;
			font-weight: 400;
			font-size: 22rpx;
			color: #2D3142;
			line-height: 42rpx;
			padding: 0 48rpx;



			::v-deep .tn-radio__label {
				font-size: 22rpx;
				color: #2D3142;
				font-weight: 400;
				margin-right: 0;
				// width: 40rpx !important;
			}

			.empower_bom {
				color: #818AA6;

				.d {
					color: #818AA6;
				}

				.txt {
					color: #2D3142;
				}
			}
		}
	}
</style>